package com.project.android;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class Lettres extends Activity implements OnClickListener{
ImageButton suivant,precedant,home,b5;
DBAdaptateur db;
int tabIM[]={R.drawable.im1,R.drawable.im2,R.drawable.im3,R.drawable.im4,R.drawable.im5,R.drawable.im6};
int idim=0,ids=0;
Cursor c;
private MediaPlayer mPlayer = null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
home=(ImageButton)findViewById(R.id.imageButton1);
suivant=(ImageButton)findViewById(R.id.imageButton2);
precedant=(ImageButton)findViewById(R.id.imageButton3);
b5=(ImageButton)findViewById(R.id.b5);
b5.setImageResource(R.drawable.im1);
suivant.setOnClickListener(this);
precedant.setOnClickListener(this);
home.setOnClickListener(this);
b5.setOnClickListener(this);
db = new DBAdaptateur(this);
db.open();
DataBind();
}

public void onClick (View v){
	switch(v.getId()){
	case R.id.imageButton2 : {
	avancer();
	b5.setImageResource(idim);}
	break;
	case R.id.imageButton3 : {
	reculer();
	b5.setImageResource(idim);
    }
	break;
	case R.id.b5 : playSon(ids); 
	break;
	case R.id.imageButton1 : {
	Intent intent=new Intent(Lettres.this,pagehomeActivity.class);
	startActivityForResult(intent,1);
	}
	break;
	}
}
public void DataBind(){
   	c =db.recupererLettre();
	startManagingCursor(c);
	c.moveToFirst();
	idim=c.getInt(1);
	ids=c.getInt(2);
	}
public void avancer(){
if(c.moveToNext() ){
idim=c.getInt(1);
ids=c.getInt(2);
}
}
public void reculer(){
if(c.moveToPrevious()){
idim=c.getInt(1);
ids=c.getInt(2);
}

}
private void playSon(int resId) {
	if(mPlayer != null) {
		mPlayer.stop();
		mPlayer.release();
	}
	mPlayer = MediaPlayer.create(this, resId);
	mPlayer.start();
}
}


